package com.masterclient.app.modules.goods.contract;

import com.eoner.baselib.presenter.ThrowableConsumer;
import com.masterclient.app.httpservice.RetrofitUtil;
import com.eoner.baselibrary.bean.goods.MiniProgramBean;

import io.reactivex.Observable;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;

public class MiniProgramPresenter extends MiniProgramContract.Presenter {
    MiniProgramContract.View view;

    public MiniProgramPresenter(MiniProgramContract.View view) {
        this.view = view;
    }

    @Override
    public void getMiniProgram(String goodid, String code) {
        Observable<MiniProgramBean> observable = RetrofitUtil.getInstance().getMiniProgram(goodid,code);

        Disposable disposable = toSubscribe(observable, new Consumer<MiniProgramBean>() {
            @Override
            public void accept(@NonNull MiniProgramBean bean) throws Exception {
                if("0".equals(bean.getCode())){
                    view.getMiniProgramSuccess(bean.getData().getSh_qrcode());
                }else{
                    view.getMiniProgramfail();
                }
            }
        }, new ThrowableConsumer());
        mRxManager.add(disposable);
    }
}
